package com.hrt.demo.fannie.service.impl;

import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hrt.demo.fannie.bean.Products;
import com.hrt.demo.fannie.dao.ProductsDao;
import com.hrt.demo.fannie.service.ProductsService;

@Service("productsService")
public class ProductsServiceImpl implements ProductsService{
	private ProductsDao productsDao;

	public ProductsDao getProductsDao() {
		return productsDao;
	}
	@Resource
	public void setProductsDao(ProductsDao productsDao) {
		this.productsDao = productsDao;
	}
	
	/**
	 * 保存实体
	 * */
	@Override
	public void addProducts(Products products) {
		try {
			this.productsDao.saveEntity(products);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 更新实体
	 * */
	@Override
	public void updateProducts(Products products) {
		try {
			this.productsDao.updateEntity(products);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	/**
	 * 删除实体
	 * */
	@Override
	public void delProducts(Long id) {
		
		try {
			this.productsDao.deleteEntity(id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 按id查询实体
	 * */
	@Override
	public Products getById(Long id) {
		
		return this.productsDao.getById(id);
	}
	
	/**
	 * 查询所有
	 * */
	@Override
	public List<Products> searchAll() {
		
		return this.productsDao.findAll();
	}

	/**
	 * 按id列表查询实体
	 * */
	@Override
	public List<Products> getByIds(Long[] ids) {
		
		return this.productsDao.getByIds(ids);
	}
	
	/**分页*/
	@Override
	public Long totalCount() {
		
		return this.productsDao.totalCount();
	}
	
	@Override
	public List<Products> queryByPage(int pageIndex, int pageSize) {
		
		return this.productsDao.queryByPage(pageIndex, pageSize);
	}
	
	/**获取数据库的当前Date形式的时间*/
	@Override
	public Timestamp getDate() {
		
		return this.productsDao.getDate();
	}
	
	/**删除选中的数据*/
	@Override
	public void deleteById(Long[] ids) throws Exception {
		List<Products> delResult = this.productsDao.getByIds(ids);
		for(Products p : delResult){
			p.setIsdelete(new Integer(1));
			this.productsDao.updateEntity(p);
		}
	}
	

}
